/**
 * Copyright (C) 2009 Noel Ang
 *
 * This file is part of Samsara.
 *
 * Samsara is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Samsara is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Samsara.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package com.lunarshades.samsara.ui;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;

/**
 * An Action that selects/deselects intervals in in the subject selection
 * model.
 *
 * @author Noel Ang, sparta.variable@gmail.com
 */
class RosterSelectToggle extends AbstractAction {

RosterSelectToggle(RosterRowSelectionModel subject) {
    super(TEXT);
    putValue(Action.MNEMONIC_KEY, MNEMONIC);
    putValue(Action.ACTION_COMMAND_KEY, ACTION_COMMAND);
    mSubject = subject;
}

public void actionPerformed(ActionEvent e) {
    int index0 = mSubject.getAnchorSelectionIndex();
    int index1 = mSubject.getLeadSelectionIndex();
    mSubject.toggleSelectionInterval(index0, index1);
}

private static final String TEXT = "Select";
private static final int MNEMONIC = KeyEvent.VK_S;

/**
 * Key for registering this action in a Swing component's ActionMap.
 */
public static final Object ACTION_COMMAND = "addToSelectionToggle";

private final RosterRowSelectionModel mSubject;
}
